<template>
  <!-- 添加或修改付款申请单对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-row :gutter="10">
      <pay-apply-detail-section :apply-id="applyId" ref="payApplyDetailSection" ></pay-apply-detail-section>
    </el-row>

    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="审计意见" prop="auditOpinion">
              <el-input type="textarea" v-model="form.auditOpinion" placeholder="请输入审计意见"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="danger" @click="submitForm('1')">退 回</el-button>
      <el-button type="primary" @click="submitForm('2')">通 过</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {accAdd, addAction, downloadFile, getAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';
import {parseTime} from "@/utils/common";
import BuyGoodsList from "@/views/develop/payApply/module/BuyGoodsList.vue";
import FileUploadShow from "@/components/FileUpload/FileUploadShow.vue";
import PayApplyDetailSection from "@/views/develop/payApply/PayApplyDetailSection.vue";

export default {
  name: "PayApplyAuditForm",
  components: {PayApplyDetailSection, FileUploadShow, BuyGoodsList},
  dicts: ["apply_pay_status", "apply_assess_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        mainId: null,
      },
      applyId:null,
      // 总条数
      total: 0,
      // 表单参数
      form: {},
      buyDetailList:[],
      payApplyBuyList:[],
      payApplyBuyDetailList:[],

      // 表单校验
      rules: {
        auditOpinion:[
          {required: true, message: '请输入审计意见', trigger: 'blur'}
        ]
      },
      url: {
        getById: '/payApply/payApply/',
        add: '/payApply/payApply/add',
        audit: '/payApply/payApply/audit',
        buyDetailList:'/goodsSalebuyall/goodsSalebuyall/list',
      },
      buyId:null,
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        buyId: null,
        invoiceCode: null,
        auditOpinion: null,
        invoicePhoto: null,
        totalMoney: null,
        paidMoney: null,
        remainMoney: null,
        assessOpinion: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "审核付款申请单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.applyId = row.id;
      getById(this.url.getById, row.id).then(response => {
        this.form = response.data;
        this.open = true;
        this.payApplyBuyList = response.data.payApplyBuyList;
        this.payApplyBuyDetailList = response.data.payApplyBuyDetailList;
        this.title = "审核付款申请单("+this.form.nos+")";
        this.loading=false;
      });
      this.buyId=row.buyId;
      this.type = row.type;
    },
    /** 提交按钮 */
    submitForm(assessStatus) {
      this.form.assessStatus = assessStatus;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.audit, this.form).then(response => {
              this.$modal.msgSuccess("审计成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
